﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAO;
using DTO;
using System.Data;

namespace BUS
{
    public class Phi_BUS
    {
        private static Phi_BUS m_instance = null;

        public static Phi_BUS Instance
        {
            get 
            {
                if (m_instance == null)
                {
                    m_instance = new Phi_BUS();
                }
                return m_instance;
            }
        }

        /// <summary>
        ///   lay danh sach phi
        /// </summary>
        /// 

        public List<Phi_DTO> LayPhi()
        {
            List<Phi_DTO> result = new List<Phi_DTO>();
            DataTable dt = Phi_DAO.Instance.LayThongTin();
            
            DataRowCollection list = dt.Rows;
            if (list.Count==0)
            {
                return result;
            }
            for (int i = 0; i < list.Count; i++)
            {
                DataRow dr = list[i];
                string _id = (string)dr["MaPhi"].ToString();
                string _name = (string)dr["TenPhi"].ToString();

                result.Add(new Phi_DTO(_id, _name));
            }
            return result;
        }

        /// <summary>
        ///   lay danh sach ma phi
        /// </summary>
        /// 

        public List<string> DanhSachMaPhi()
        {
            List<string> result = new List<string>();

            DataTable dt = Phi_DAO.Instance.LayToanBoMaPhi();
            DataRowCollection list = dt.Rows;
            if (list.Count == 0)
            {
                return null;
            }

            for (int i = 0; i < list.Count;i++ )
            {
                DataRow dr = list[i];
                string _id = (string)dr["MaPhi"];
                result.Add(_id);

            }
            return result;
        }

        public string LayThongTinPhi(Phi_DTO item)
        {
            string result = "";
            DataTable dt = Phi_DAO.Instance.LayThongTinPhi(item.MaPhi);
            DataRowCollection list = dt.Rows;
            if (list.Count == 0)
            {
                return null;
            }
            DataRow dr = list[0];
            result = (string)dr["TenPhi"];
            return result;
        }

        /// <summary>
        ///   them khoan phi moi
        /// </summary>
        /// 
        public bool ThemPhi(Phi_DTO item)
        {
            return Phi_DAO.Instance.ThemPhi(item.TenPhi);
        }

        /// <summary>
        ///   sửa phí
        /// </summary>
        /// 
        public bool SuaPhi(Phi_DTO item)
        {
            return Phi_DAO.Instance.SuaPhi(item.MaPhi, item.TenPhi);
        }

        /// <summary>
        ///   xoa phi
        /// </summary>
        /// 
        public bool XoaPhi(Phi_DTO item)
        {
            return Phi_DAO.Instance.XoaPhi(item.MaPhi);
        }
    }
}
